package com.recipe.controller;
import com.alibaba.fastjson.JSON;
import com.recipe.common.config.RedisUtil;
import com.recipe.common.entity.Result;
import com.recipe.entity.RecommendDish;
import com.recipe.entity.User;
import com.recipe.service.UserService;
import com.recipe.service.impl.Recommend;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
 * @author lzk
 * @date 2024-06-14 11:40:59
 * @description
 */
@RestController
@RequestMapping("test")
public class testController {

    @Resource
    Recommend recommend;


    @Resource
    RocketMQTemplate rocketMQTemplate;

    @Resource
    RedisUtil redisUtil;
    @Resource
    UserService userService;

    @GetMapping("/testString")
    public String test1(){
        return "test";
    }



    @GetMapping("/redis")
    public Result<Boolean> testRedis(){
        List<User> list = userService.list();
        redisUtil.set("test", JSON.toJSONString(list));
        return Result.ok();
    }

    @GetMapping("/redis2")
    public Result<List<User>> testRedis1(){
        String test = redisUtil.get("test");
        List<User> users=(List<User>)JSON.parse(test);
        return Result.ok(users);
    }

    @PostMapping("/pushMessage")
    public Result<Boolean> pushMessage(@Param("id") int id) {
        rocketMQTemplate.convertAndSend("test-topic", "666" + id);

        return Result.ok(true);
    }

}
